/**
 * @author: HenryDai
 * @Date: 2022/04/29 13:31
 * @description:
 */
public class SoldState implements State{

    @Override
    public void insertCoins(VendingMachine machine) {
        System.out.println("操作错误: 销售状态, 不许允许投币");
    }

    @Override
    public void backCoins(VendingMachine machine) {
        System.out.println("操作错误: 销售状态, 不许允许退钱");
    }

    @Override
    public void pressButton(VendingMachine machine) {
        System.out.println("操作错误: 销售状态, 不许允许按键");
    }

    @Override
    public void distributeGood(VendingMachine machine) {
        System.out.println("操作正确: 销售状态, 正在出货");
        int count = machine.getGoodCount();
        machine.setGoodCount(--count);
        State state = null;
        if(count==0)
        {
            state = new SoldOutState();
        }
        else
        {
            state = new NoMoneyState();
        }
        machine.setState(state);
    }
}
